package com.cjj2016.cjj.wandoujiaanimationdemo;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.cjj2016.cjj.wandoujiaanimationdemo.adapter.MyRecyclerAdapter;
import com.cjj2016.cjj.wandoujiaanimationdemo.utils.DisplayUtil;
import com.cjj2016.cjj.wandoujiaanimationdemo.widget.DividerItemDecoration;

public class MainActivity extends AppCompatActivity {

    private RecyclerView recyclerView;

    private Object[][] mImageTextArray = new Object[][] {
            {R.drawable.ic_aqy, "爱奇艺"}, {R.drawable.ic_bb, "哔哩哔哩"},
            {R.drawable.ic_cz, "赤足"}, {R.drawable.ic_kk, "快看"},
            {R.drawable.ic_kr, "kingRoot"}, {R.drawable.ic_sg, "搜狗"},
            {R.drawable.ic_xl, "迅雷"}, {R.drawable.ic_yk, "优酷"},
            {R.drawable.ic_yyy, "网易云音乐"}, {R.drawable.ic_qq, "QQ"}
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //去掉状态栏
        DisplayUtil.hideStatusBar(getWindow());

        setContentView(R.layout.activity_main);

        initView();
        initData();
        initListener();
    }


    private void initView() {

        recyclerView = (RecyclerView) findViewById(R.id.recyclerview);

    }


    private void initData() {
        MyRecyclerAdapter myRecyclerAdapter = new MyRecyclerAdapter(this,mImageTextArray);
        myRecyclerAdapter.setMyOnItemClickListener(new MyRecyclerAdapter.MyOnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                Object[] object = mImageTextArray[position];
                int imgid = (int) object[0];
                String appname = (String) object[1];
                int itemViewMarginTop = view.getTop() +getResources().getDimensionPixelOffset(R.dimen.bar_view_height);

                Intent intent = new Intent(MainActivity.this,TestActivity.class);
                intent.putExtra("ItemViewMarginTop",itemViewMarginTop);
                intent.putExtra("imageRid",imgid);
                intent.putExtra("appName",appname);
                startActivity(intent);

                //去掉默认加载activity动画
                overridePendingTransition(0,0);
            }
        });

        recyclerView.setLayoutManager( new LinearLayoutManager(this));
        //添加分割线
        recyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL_LIST));
        recyclerView.setAdapter(myRecyclerAdapter);


    }


    private void initListener() {

    }



}
